"use strict";
cc._RF.push(module, '345c2692y5AqYYOT+iXw0yE', 'ArmyGroupController');
// scripts/ArmyGroupController.js

"use strict";

var e = require;
var t = module;
var n,
    o = (n = e("SoundMgr")) && n.__esModule ? n : {
  "default": n
};
window.ArmyGroupController = {
  Instance: null
};
var i = e("LevelManager");
cc.Class({
  "extends": cc.Component,
  properties: {
    TargetAvatarControllerType: {
      type: cc.Enum(i.AvatarControllerType),
      "default": i.AvatarControllerType.BlackKiller
    },
    TargetAvatarNode: cc.Node,
    TargetControllerDistanceMinLimit: 2,
    TargetControllerObjects: {
      type: [cc.Node],
      "default": []
    },
    ArmyControllerAnimation: cc.Animation,
    UpdateFlag: 0,
    ComeBackDistanceLimit: 20,
    ComeBackStartPosition: {
      type: cc.v2,
      "default": cc.v2(0, 0)
    }
  },
  onLoad: function onLoad() {
    ArmyGroupController.Instance = this;
  },
  start: function start() {
    o["default"].Instance.playSoundClip(AssetManager.Instance.AudioClips[3]);
  },
  update: function update(e) {
    switch (this.UpdateFlag) {
      case 0:
        if (this.node.position.sub(this.TargetAvatarNode.position).mag() > this.TargetControllerDistanceMinLimit) this.node.x += LevelManager.Instance.AvatarControllerFastMoveSpeed * e;else {
          this.UpdateFlag = 1;
          this.onArmyGetJailed(this.TargetAvatarControllerType == i.AvatarControllerType.BlackKiller);
        }
        break;

      case 1:
        if (this.node.position.sub(this.ComeBackStartPosition).mag() > this.ComeBackDistanceLimit) {
          this.UpdateFlag = 2;
          JailSceneContent.Instance.Show(this.TargetAvatarControllerType);
          this.node.destroy();
        } else this.node.x -= LevelManager.Instance.AvatarControllerFastMoveSpeed * e;

    }
  },
  onArmyGetJailed: function onArmyGetJailed(e) {
    this.ComeBackStartPosition = this.node.position;
    this.ArmyControllerAnimation.play("WalkDrag");
    this.ArmyControllerAnimation.node.scaleX = -this.ArmyControllerAnimation.node.scaleX;
    var t = this.TargetAvatarNode.position;
    this.TargetAvatarNode.destroy();
    null != this.TargetControllerObjects[this.TargetAvatarControllerType] && (this.TargetControllerObjects[this.TargetAvatarControllerType].active = !0);
    this.CheckTargetCallback = this.schedule(function () {
      if (null == this.TargetAvatarNode.parent) {
        if (e) {
          var n = cc.instantiate(AssetManager.Instance.ControllerPrefabs[2]);
          n.parent = LevelManager.Instance.SceneContentNode;
          n.position = cc.v2(t.x - 700, t.y);
        } else LevelManager.Instance.CreateRandomNPCKiller();

        this.unscheduleAllCallbacks();
      }
    }, 0, cc.macro.REPEAT_FOREVER, 0);
  }
});

cc._RF.pop();